import re

# 1、读取数据
with open("../../data/log.log", mode="r", encoding="utf-8") as f:
    lines = [line.strip() for line in f.readlines()]

with open("../../data/log_dec.log", mode="w", encoding="utf-8") as f:
    # 2、解析数据
    for line in lines:
        # 获取日志类型
        type = re.search("^\[([A-Z]{3,6})]", line).group(1)

        # 打印日志的时间
        time = re.search("\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}", line).group()

        # 匹配类名
        clazz = re.search("([A-Za-z]+\w+\.)+\w+", line).group()

        # 获取日志描述信息
        desc = re.search("- (.*)$", line).group(1)

        # 保存到文件中
        f.write(f"{type}\t{time}\t{clazz}\t{desc}\n")
